package com.ciwong.epaper.modules.epaper.ui;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.ciwong.epaper.R;
import com.ciwong.epaper.application.EApplication;
import com.ciwong.epaper.application.EpaperConstant;
import com.ciwong.epaper.modules.epaper.adapter.AddBookAdapter;
import com.ciwong.epaper.modules.epaper.adapter.AddBookPopupAdapter;
import com.ciwong.epaper.modules.epaper.bean.BookCaseBean;
import com.ciwong.epaper.modules.epaper.bean.ChooseGradeBean;
import com.ciwong.epaper.modules.epaper.bean.EpaperInfo;
import com.ciwong.epaper.modules.epaper.dao.EpaperDao;
import com.ciwong.epaper.modules.epaper.dao.EpaperRequest;
import com.ciwong.epaper.modules.epaper.util.EpaperJumpManager;
import com.ciwong.epaper.modules.me.bean.Clazz;
import com.ciwong.epaper.modules.me.bean.Service;
import com.ciwong.epaper.modules.me.bean.ServiceDetail;
import com.ciwong.epaper.modules.me.util.MeJumpManager;
import com.ciwong.epaper.util.BaseExtCallBack;
import com.ciwong.epaper.util.DialogUtil;
import com.ciwong.epaper.util.DoubleClickCheckUtils;
import com.ciwong.epaper.util.EConstants;
import com.ciwong.epaper.util.IntentValue;
import com.ciwong.epaper.util.RequestCode;
import com.ciwong.epaper.util.SerializableManager;
import com.ciwong.epaper.widget.PullToRefreshView;
import com.ciwong.libs.utils.CWLog;
import com.ciwong.libs.utils.CWSys;
import com.ciwong.libs.utils.NetworkUtils;
import com.ciwong.libs.widget.CWToast;
import com.ciwong.mobilelib.i.BaseCallBack;
import com.ciwong.mobilelib.i.ViewOnClickListener;
import com.ciwong.mobilelib.ui.BaseActivity;
import com.ciwong.mobilelib.utils.BaseIntentFlag;
import com.ciwong.mobilelib.utils.ToastUtil;
import com.ciwong.mobilelib.widget.CWDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * 书柜 、全部 我的书籍 页面
 * By:xy
 * Time:2016/08/05
 */
public class AddBookActivity extends BaseActivity implements
        PullToRefreshView.OnHeaderRefreshListener,
        PullToRefreshView.OnFooterRefreshListener, View.OnClickListener {

    public String TAG = "AddBookActivity";

    private ListView addBookLV, popListView;

    private List<EpaperInfo> mEpaperInfos;

    //当前在选服务列表中的所有服务列表的全局变量  通过选服务可更改其选中状态
    private List<ServiceDetail> currentPopWinDetailList;

    private AddBookAdapter addBookAdapter;

    private View noDataView, ll_noNet, popupView, footView, topView;

    private TextView shopTv, promptTv, promptTv2, confirmTv;
    private Button mBtnRetry;

    private EApplication mEApplication;


    private Handler handler = new Handler();

    /**
     * popupWindow适配器
     */
    private AddBookPopupAdapter popAdapter;

    /**
     * 刷新ListView
     */
    private PullToRefreshView mRefreshView;

    /**
     * 默认从第一页开始加载
     */
    private final int defult_page = 1;

    /**
     * 当前页码
     */
    private int curPage = defult_page;

    /**
     * 默认加载数据大小
     */
    private static final int LOAD_PAGE_SIZE = 30;

    /**
     * 刷新书桌目录
     */
    public static final int REFRESH_LOCAL_BOOK_LIST = 1;

    private Service mService;

    private boolean fromBookShop = false;

    private boolean next = false;


    private boolean fromAddBook = true;

    private CWDialog mErrorDialog = null;

    /**
     * 从CatalogActivity传递回来的标识
     */
    private boolean mIsClose = false;


    /**
     * 年级选择
     */
    private LinearLayout ll_grade_choose;
    /**
     * 选择服务
     */
    private LinearLayout ll_service_choose;
    private ChooseGradeDialog chooseGradeDialog;
    private ChooseServiceDialog chooseServiceDialog;
    private TextView tv_grade;
    private Clazz clazz;
    private TextView tv_service_name;

    @Override
    protected void preCreate() {
        Intent intent = getIntent();
        //是否来自购买
        fromBookShop = intent.getBooleanExtra("fromBookShop", false);
        next = intent.getBooleanExtra("jumpToService", false);
        mService = (Service) intent.getSerializableExtra("service");
    }

    @Override
    protected int setView() {
        return R.layout.activity_add_book;
    }

    /**
     * 搜索书籍按钮
     */
    LinearLayout ll_search_book;

    @Override
    protected void findViews() {
        addBookLV = (ListView) findViewById(R.id.add_book_lv);
        ll_search_book = (LinearLayout) findViewById(R.id.ll_search);
        noDataView = findViewById(R.id.ll_no_data);
        ll_noNet = findViewById(R.id.ll_no_net);
        tv_grade = (TextView) findViewById(R.id.tv_grade);
        mRefreshView = (PullToRefreshView) findViewById(R.id.add_book_refresh_view);
        ll_grade_choose = (LinearLayout) findViewById(R.id.ll_grade_choose);
        ll_service_choose = (LinearLayout) findViewById(R.id.ll_service_choose);
        shopTv = (TextView) findViewById(R.id.tv_go_to_resource_center);
        promptTv = (TextView) findViewById(R.id.tv_no_work_from_teacher_tip);
        promptTv2 = (TextView) findViewById(R.id.tv_no_work_from_teacher_tip2);
        mBtnRetry = findViewById(R.id.btn_retry);
        popupView = LayoutInflater.from(this).inflate(R.layout.dialog_booklist, null);
        popListView = (ListView) popupView.findViewById(R.id.dialog_booklist_list);
        footView = View.inflate(this, R.layout.list_foot_booklist, null);
        topView = View.inflate(this, R.layout.list_top_booklist, null);
        confirmTv = (TextView) topView.findViewById(R.id.yes_tv);
        popListView.addFooterView(footView);
        popListView.addHeaderView(topView, null, false);
        tv_service_name = (TextView) findViewById(R.id.tv_service_name);

    }

    @Override
    protected void initEvent() {
        mRefreshView.setOnHeaderRefreshListener(this);
        mRefreshView.setOnFooterRefreshListener(this);
        ll_grade_choose.setOnClickListener(this);
        ll_service_choose.setOnClickListener(this);

        addBookLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                if (DoubleClickCheckUtils.vertifyDuration()) {
                    EpaperInfo epaperInfo = (EpaperInfo) addBookAdapter.getItem(position);
                    if (epaperInfo != null) {
                        if (epaperInfo.getIsFree() == 1 || epaperInfo.getIsExpire() == 1) {
                            EpaperJumpManager.jumpToCatalog(R.string.go_back,
                                    AddBookActivity.this,
                                    (EpaperInfo) addBookAdapter.getItem(position),
                                    IntentValue.JumpToBookCatalogType.FROM_ADD_BOOK, RequestCode.AddBookActivityResquestCode.REQ_CODE_JUMP_TO_BOOK_DIRECTORY, epaperInfo == null ? -1 : epaperInfo.getServerId());
                        } else {
                            MeJumpManager.jumpBuyService(AddBookActivity.this, R.string.go_back, epaperInfo.getServerId(), -1, RequestCode.MainActivityResquestCode.REQUEST_CODE_TO_PAY, "");
                        }
                    }

                }

            }
        });

//        setRightBtnListener(new ViewOnClickListener() {
//            @Override
//            public void avertRepeatOnClick(View view) {
//                MeJumpManager.jumpServices(R.string.go_back, AddBookActivity.this, REQ_CODE_JUMP_TO_SERVICE_LIST);
//                MeJumpManager.jumpToResourseCenterH5Activity(AddBookActivity.this,R.string.go_back,getResources().getString(R.string.resource_center));
        //跳转到教辅商城
//                setResult(Activity.RESULT_OK);
//                finish();
//            }
//        });

        shopTv.setOnClickListener(new ViewOnClickListener() {
            @Override
            public void avertRepeatOnClick(View v) {
                //跳转至微商城页面
//                MeJumpManager.jumpServices(R.string.go_back, AddBookActivity.this,
//                        REQ_CODE_JUMP_TO_SERVICE_LIST);
                MeJumpManager.jumpToResourseCenterH5Activity(AddBookActivity.this, R.string.go_back, getResources().getString(R.string.resource_center));
//                setResult(Activity.RESULT_OK);
//                finish();

            }
        });

        mBtnRetry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (NetworkUtils.isOnline()) {
                    //重新请求服务状态 与本地比对  不来自购买
//                    getServiceState(false);
                    getServicesList(false);
                    curPage = 1;
                    getEpageUserProduct(curPage);
                } else {
                    toastInTop("当前网络不可用，请检查你的网络设置！");
                }

            }
        });
        ll_search_book.setOnClickListener(this);

    }


    @Override
    protected void init() {
        mEApplication = (EApplication) getApplication();
        addBookAdapter = new AddBookAdapter(this, AddBookAdapter.ADD_TYPE_NO,
                null, fromAddBook);
        addBookLV.setAdapter(addBookAdapter);
        setTitleText("我的书籍");
//        setRightBtnText(getResources().getString(R.string.resource_center));
        popAdapter = new AddBookPopupAdapter(AddBookActivity.this, null);
        popListView.setAdapter(popAdapter);
        currentPopWinDetailList = new ArrayList<ServiceDetail>();


        clazz = mEApplication.getClazz();
        if (clazz != null) {
            grade = clazz.getGradeId() + "";
            if (TextUtils.isEmpty(grade)) {
                grade = "0";
                tv_grade.setText("全部年级");
            } else if (grade.equals("1101")) {
                tv_grade.setText("一年级");
            } else if (grade.equals("1102")) {
                tv_grade.setText("二年级");
            } else if (grade.equals("1103")) {
                tv_grade.setText("三年级");
            } else if (grade.equals("1104")) {
                tv_grade.setText("四年级");
            } else if (grade.equals("1105")) {
                tv_grade.setText("五年级");
            } else if (grade.equals("1106")) {
                tv_grade.setText("六年级");
            } else if (grade.equals("1107")) {
                tv_grade.setText("七年级");
            } else if (grade.equals("1108")) {
                tv_grade.setText("八年级");
            } else if (grade.equals("1109")) {
                tv_grade.setText("九年级");
            } else if (!grade.equals("1107") && !grade.equals("1108") && !grade.equals("1109")) {
                grade = "333333";
                tv_grade.setText("其他");
            }
        } else {
            grade = "0";
            tv_grade.setText("全部年级");
        }
        registerBoradcastReceiver();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        CWLog.d("lzh==>> ", "onNewIntent");
        loadData();
    }

    @Override
    protected void loadData() {

        if (next) {
//            MeJumpManager.jumpServices(R.string.go_back, AddBookActivity.this,
//                    AddBookActivity.REQ_CODE_JUMP_TO_SERVICE_LIST);
            MeJumpManager.jumpToResourseCenterH5Activity(this, R.string.go_back, getResources().getString(R.string.resource_center));
        } else {
            //设置本ID非首次登录
            CWSys.setSharedBoolean(EConstants.SHARE_KEY_IS_FIRST_LOGIN + SerializableManager.getInstance().getUserId(true), false);

        }
        getServicesList(false);
        getEpageUserProduct(curPage);
    }

    private List<EpaperInfo.Server> serverList = new ArrayList<EpaperInfo.Server>();

    /**
     * 获取用户可用的服务列表
     */
    private void getServicesList(final boolean isShowChooseGradeDialog) {
        if (!NetworkUtils.isOnline()) {
            ToastUtil.INSTANCE.toastCenterNoNetError();
            return;
        }
        showCricleProgress();
        EpaperRequest.getServicesList(EApplication.BRAND_ID + "", new BaseExtCallBack(AddBookActivity.this, getUserInfoBase().getUserId() + "") {
            @Override
            public void success(Object data) {
                if (data != null) {
                    serverList.clear();
                    serverList.addAll((List<EpaperInfo.Server>) data);
                    if (serverList.size() > 1) {
                        EpaperInfo.Server server = new EpaperInfo.Server();
                        server.setId(0);
                        server.setName("全部书籍");
                        server.setLogo(serverList.get(0).getLogo());
                        serverList.add(0, server);
                    }

                    hideCricleProgress();
                    if (isShowChooseGradeDialog) {
                        if (chooseServiceDialog == null) {
                            chooseServiceDialog = new ChooseServiceDialog(AddBookActivity.this, serverList, onServicesItemClickLister);
                        }
                        chooseServiceDialog.show();
                    }
                }
            }

            @Override
            public void failed(Object data) {
                hideCricleProgress();
                super.failed(data);
            }

            @Override
            public void failed(int errorCode, Object data) {
                hideCricleProgress();
                super.failed(errorCode, data);
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        if (resultCode == RESULT_OK) {
            curPage = 1;
            getEpageUserProduct(curPage);
        }
        //添加书籍成功之后
        if (requestCode == RequestCode.AddBookActivityResquestCode.REQ_CODE_JUMP_TO_BOOK_DIRECTORY) {
            if (resultCode == RESULT_OK) {
                //获取从CatalogActivity传递回来的数据
                final EpaperInfo epaperInfo = (EpaperInfo) data
                        .getSerializableExtra(
                                BaseIntentFlag.INTENT_FLAG_OBJ);

                mIsClose = data.getBooleanExtra(EpaperConstant.CLOSE_ADDBOOKACTIVITY, false);
                if (epaperInfo == null) {
                    return;
                }
            }
            //从微商城购买或体验服务成功后
        } else if (requestCode == RequestCode.AddBookActivityResquestCode.REQ_CODE_JUMP_TO_SERVICE_LIST) {
            if (resultCode == RESULT_OK && data != null) {
                //从书柜跳到微商城回调到书柜逻辑
                mService = (Service) data.getSerializableExtra(BaseIntentFlag.INTENT_FLAG_OBJ);
            }
        } else if (requestCode == RequestCode.AddBookActivityResquestCode.REQ_CODE_TO_SEARCH_BOOK && resultCode == Activity.RESULT_OK) {//搜索书籍而来
            //更新列表
            Log.d(TAG, "####搜索书籍而来########");
            setResult(RESULT_OK);

        }
    }


    /**
     * 获取缓存书籍列表key
     *
     * @return
     */
    private String getSerilizeBookListKey() {

        return SerializableManager.SerializeKey.SHARE_KEY_BOOKCASE;
    }


    /**
     * 底部刷新
     *
     * @param view
     */
    @Override
    public void onFooterRefresh(PullToRefreshView view) {
        if (!NetworkUtils.isOnline()) {
            CWToast.makeText(AddBookActivity.this, getString(R.string.connect_disable), Toast.LENGTH_LONG).setToastType(CWToast.TOAST_TYPE_ERROR).show();
            return;
        }
        curPage++;
        getEpageUserProduct(curPage);
    }

    /**
     * 头部刷新
     *
     * @param view
     */
    @Override
    public void onHeaderRefresh(PullToRefreshView view) {
        curPage = 1;
        getEpageUserProduct(curPage);
    }

    /**
     * 获取服务状态
     * 修改与书柜逻辑直接取网络数据 by young 2016/09/11
     */

    /**
     * 添加书籍到书柜记录(上传到服务器)
     */
    public void setBookcaseToServer(final EpaperInfo epaperInfo) {
        showCricleProgress();
        EpaperDao.getInstance().setBookcaseToServer(EApplication.BRAND_ID, epaperInfo.getPackageId()
                , epaperInfo.getServerId(), new BaseExtCallBack(AddBookActivity.this, EApplication.getInstance().getUserInfoBase().getUserId() + "") {

                    @Override
                    public void failed(int errorCode, Object data) {
                        CWLog.i("TAT", "【CatalogActivity】 上传书柜记录 failed！");
                        super.failed(errorCode, data);
                        hideCricleProgress();
                        toastInTop("添加失败，请稍后重试");
                        DialogUtil.showFailedToastByErrorType(AddBookActivity.this, data);

                    }

                    @Override
                    public void failed(Object data) {
                        super.failed(data);
                        hideCricleProgress();
                        toastInTop("添加失败，请稍后重试");
                        DialogUtil.showFailedToastByErrorType(AddBookActivity.this, data);

                    }

                    @Override
                    public void success(Object data) {
                        epaperInfo.isBookCase = 1;
                        toastInTop("1本书已添加到书桌");
                        setResult(RESULT_OK);
                        addBookAdapter.notifyDataSetChanged();
//                        deleteLocalBookList(epaperInfo, true);
                        hideCricleProgress();
                    }
                });
    }


    /**
     * 添加书籍失败
     */
    public void showErrorDialog() {
        mErrorDialog = new CWDialog(AddBookActivity.this, false, false)
                .setMessage(getString(R.string.error_add_book), 16, Color.BLACK)
                .setPositiveButton("确定", null, true,
                        getResources().getDrawable(R.drawable.dialog_floor_selector));
        mErrorDialog.show();

    }

    private List<ChooseGradeBean> chooseGradeBeanList = new ArrayList<ChooseGradeBean>();
    private AdapterView.OnItemClickListener onGradeItemClickLister = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ChooseGradeBean chooseGradeBean = chooseGradeBeanList.get(position);
            grade = chooseGradeBean.grade;
            tv_grade.setText(chooseGradeBean.title);
            curPage = 1;
            getEpageUserProduct(curPage);
            if (chooseGradeDialog != null && chooseGradeDialog.isShowing()) {
                chooseGradeDialog.dismiss();
            }
        }
    };
    /**
     * 默认选中的服务
     */
    private String serviceId = "0";
    private AdapterView.OnItemClickListener onServicesItemClickLister = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String serviceId = serverList.get(position).getId() + "";
            AddBookActivity.this.serviceId = serviceId;
            tv_service_name.setText(serverList.get(position).getName());
            curPage = 1;
            getEpageUserProduct(curPage);
            if (chooseServiceDialog != null) {
                chooseServiceDialog.dismiss();
            }
        }
    };

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ll_service_choose) { //选择服务
            if (serverList.size() < 1) {
                getServicesList(true);
            } else {
                if (chooseServiceDialog == null) {
                    chooseServiceDialog = new ChooseServiceDialog(AddBookActivity.this, serverList, onServicesItemClickLister);
                }
                chooseServiceDialog.show();
            }

        } else if (id == R.id.ll_grade_choose) {//选择年级
            if (chooseGradeBeanList.size() < 1) {
                createGradeListBean();
            }
            if (chooseGradeDialog == null) {
                chooseGradeDialog = new ChooseGradeDialog(this, chooseGradeBeanList, onGradeItemClickLister);
            }
            chooseGradeDialog.show();
        } else if (id == R.id.ll_search) {
            EpaperJumpManager.jumpToSerachBook(R.string.go_back, AddBookActivity.this, RequestCode.AddBookActivityResquestCode.REQ_CODE_TO_SEARCH_BOOK);
        }
    }

    private boolean isFirstLoad = true;

    private void getEpageUserProduct(final int pageIndex) {
        if (!NetworkUtils.isOnline()) {
            if (isFirstLoad) {
                showNetErrorView();
            } else {
                toastInTop("网络不可用，请连接网络后重试!");
            }
            return;
        }
        isFirstLoad = false;
        EpaperRequest.getUserProductByKey(EApplication.BRAND_ID + "", grade, serviceId, "", pageIndex, LOAD_PAGE_SIZE, new BaseCallBack() {
            @Override
            public void success(Object data) {
                hideCricleProgress();
                mRefreshView.onFooterRefreshComplete();
                mRefreshView.onHeaderRefreshComplete();
                if (data != null) {
                    BookCaseBean bookCaseBean = (BookCaseBean) data;
                    if (pageIndex == 1) {
                        addBookAdapter.clear();
                    }
                    if (bookCaseBean.product.size() < 1 && pageIndex == 1) {
                        showEmptyView();
                    } else {
                        addBookAdapter.addAll(bookCaseBean.product);
                        showNormalView();
                    }

                    if (addBookAdapter.getCount() == bookCaseBean.pageCount) {
                        mRefreshView.setFooterState(PullToRefreshView.PULL_TO_NO_MORE);
                    } else {
                        mRefreshView.setFooterState(PullToRefreshView.PULL_TO_REFRESH);
                    }
                }
            }

            @Override
            public void failed(int errorCode, Object data) {
                mRefreshView.onFooterRefreshComplete();
                mRefreshView.onHeaderRefreshComplete();
                hideCricleProgress();
                showNetErrorView();
            }

            @Override
            public void failed(Object data) {
                mRefreshView.onFooterRefreshComplete();
                mRefreshView.onHeaderRefreshComplete();
                hideCricleProgress();
                showNetErrorView();
            }
        });
    }

    private void showEmptyView() {
        noDataView.setVisibility(View.VISIBLE);
        mRefreshView.setVisibility(View.GONE);
        ll_noNet.setVisibility(View.GONE);
    }

    private void showNormalView() {
        noDataView.setVisibility(View.GONE);
        mRefreshView.setVisibility(View.VISIBLE);
        ll_noNet.setVisibility(View.GONE);
    }

    private void showNetErrorView() {
        noDataView.setVisibility(View.GONE);
        mRefreshView.setVisibility(View.GONE);
        ll_noNet.setVisibility(View.VISIBLE);
    }

    /**
     * 默认选中的年级
     */
    private String grade = "0";

    private void createGradeListBean() {
//        {@"1101":@"一年级",\
//            @"1102":@"二年级",\
//            @"1103":@"三年级",\
//            @"1104":@"四年级",\
//            @"1105":@"五年级",\
//            @"1106":@"六年级",\
//            @"1107":@"七年级",\
//            @"1108":@"八年级",\
//            @"1109":@"九年级",\
//            @"1110":@"",\
//            @"1111":@"高一",\
//            @"1112":@"高二",\
//            @"1113":@"高三",\
//            @"1114":@"小班",\
//            @"1115":@"中班",\
//            @"1116":@"大班",\
//            @"1117":@"学前班",\
//            @"1118":@"大一",\
//            @"1119":@"大二",\
//            @"1120":@"大三",\
//            @"1121":@"大四",}
        chooseGradeBeanList.add(new ChooseGradeBean("全部年级", "全", "0"));
        chooseGradeBeanList.add(new ChooseGradeBean("九年级", "9", "1109"));
        chooseGradeBeanList.add(new ChooseGradeBean("八年级", "8", "1108"));
        chooseGradeBeanList.add(new ChooseGradeBean("七年级", "7", "1107"));
        chooseGradeBeanList.add(new ChooseGradeBean("六年级", "6", "1106"));
        chooseGradeBeanList.add(new ChooseGradeBean("五年级", "5", "1105"));
        chooseGradeBeanList.add(new ChooseGradeBean("四年级", "4", "1104"));
        chooseGradeBeanList.add(new ChooseGradeBean("三年级", "3", "1103"));
        chooseGradeBeanList.add(new ChooseGradeBean("二年级", "2", "1102"));
        chooseGradeBeanList.add(new ChooseGradeBean("一年级", "1", "1101"));
        chooseGradeBeanList.add(new ChooseGradeBean("其他", "其", "333333"));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver();
    }

    private void registerBoradcastReceiver() {
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction(EpaperConstant.BROADCAST_AUTONOMIC_STUDY_STATUS_CHANGE_MSG);
        //注册广播
        registerReceiver(mBroadcastReceiver, myIntentFilter);
    }

    BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent == null) {
                return;
            }
            if (EpaperConstant.BROADCAST_AUTONOMIC_STUDY_STATUS_CHANGE_MSG.equals(intent.getAction())) {
                getServicesList(false);
                getEpageUserProduct(curPage);
            }
        }
    };

    private void unregisterReceiver() {
        if (mBroadcastReceiver != null)
            unregisterReceiver(mBroadcastReceiver);
    }

}
